package com.teacher.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.teacher.common.CommonResult;
import com.teacher.common.JwtTokenUtil;
import com.teacher.mapper.PerStudentMapper;
import com.teacher.mapper.TermMapper;
import com.teacher.pojo.entity.*;
import com.teacher.pojo.enums.items.*;
import com.teacher.pojo.vo.all.ClassLevelGetVo;
import com.teacher.pojo.vo.all.ProjectItem;
import com.teacher.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

@Service
public class IAllServiceImpl implements IAllService {

    @Autowired
    private JwtTokenUtil jwtTokenUtil;

    @Autowired
    private HttpServletRequest httpServletRequest;

    @Autowired
    private TermMapper termMapper;

    @Autowired
    private PerStudentMapper perStudentMapper;

    @Autowired
    private IPerStudentService iPerStudentService;

    @Autowired
    private IRewardDistributionService iRewardDistributionService;

    @Autowired
    private IStuClassService iStuClassService;

    /**
     * 德育基础分
     */
    @Autowired
    private IMoralEducationBasicService iMoralEducationBasicService;

    /**
     * 院级优秀党员...优秀团员
     */
    @Autowired
    private IMoralEducationService iMoralEducationService;

    /**
     * 党校学习
     */
    @Autowired
    private IPartySchoolService iPartySchoolService;

    /**
     * 入党积极分子
     */
    @Autowired
    private IPartyActivistsService iPartyActivistsService;

    /**
     * 热心公益活动
     */
    @Autowired
    private IPublicWelfareActivitiesService iPublicWelfareActivitiesService;

    /**
     * 好人好事
     */
    @Autowired
    private IGoodThingsService iGoodThingsService;

    /**
     * 暑期三下乡
     */
    @Autowired
    private ISummerVolunteerService iSummerVolunteerService;

    /**
     * 学生干部任职
     */
    @Autowired
    private IJobService iJobService;

    /**
     * 学业成绩
     */
    @Autowired
    private IStudyGradesService iStudyGradesService;

    /**
     * 证书分
     */
    @Autowired
    private ICertificateService iCertificateService;

    /**
     * 创新创业
     */
    @Autowired
    private IInnovativeUndertakingService iInnovativeUndertakingService;

    /**
     * 体育专业体育成绩
     */
    @Autowired
    private IPhysicalEducationMajorService iPhysicalEducationMajorService;

    /**
     * 非体育专业成绩
     */
    @Autowired
    private IPhysicalEducationNormalService iPhysicalEducationNormalService;

    /**
     * 美育基本分
     */
    @Autowired
    private IAestheticEducationBasicService iAestheticEducationBasicService;

    /**
     * 文艺活动分
     */
    @Autowired
    private ICulturalActivitiesRewardService iCulturalActivitiesRewardService;

    /**
     * 日常行为规范分
     */
    @Autowired
    private IBehaviorService iBehaviorService;

    /**
     * 实习成绩
     */
    @Autowired
    private IPracticeGradesService iPracticeGradesService;

    /**
     * 寝室总评等级
     */
    @Autowired
    private IBedroomLevelService iBedroomLevelService;

    /**
     * 寝室荣誉
     */
    @Autowired
    private IBedroomGloryService iBedroomGloryService;

    /**
     * 志愿者服务小时数
     */
    @Autowired
    private IVolunteerService iVolunteerService;

    /**
     * 星级志愿者
     */
    @Autowired
    private IVolunteerStarService iVolunteerStarService;

    /**
     * 学科竞赛
     */
    @Autowired
    private ICourseContestsService iCourseContestsService;

    /**
     * 班级考核分
     */
    @Autowired
    private IClassLevelService iClassLevelService;

    /**
     * 班级评价分
     */
    @Autowired
    private IClassFractionService iClassFractionService;

    /**
     * 违反四项基本原则
     */
    @Autowired
    private IFourPrincipleService iFourPrincipleService;

    /**
     * 处分
     */
    @Autowired
    private IPunishmentService iPunishmentService;

    /**
     * 旷课
     */
    @Autowired
    private IAbsentClassService iAbsentClassService;

    /**
     * 班级活动缺席
     */
    @Autowired
    private IAbsentActivitiesService iAbsentActivitiesService;

    /**
     * 文化传播
     */
    @Autowired
    private ICulturalTransmissionService iCulturalTransmissionService;

    /**
     * 查询本学期成绩表
     *
     * @return
     */
    @Override
    public CommonResult<List<ProjectItem>> getCurrentTermData(String studentKey) {
        if (StrUtil.isEmpty(studentKey)) {
            studentKey = jwtTokenUtil.getUsernameByRequest(httpServletRequest);
        }

        Long currentTermId = termMapper.getCurrentTerm();
        List<ProjectItem> projectItemList = new ArrayList<>();


        // 德育
        ProjectItem moralGrades = new ProjectItem();
        moralGrades.setMaxGrades(new BigDecimal(13));
        moralGrades.setKey("德育素质测评");
        moralGrades.setChildList(getMoralData(studentKey, currentTermId));

        // 计算德育素质测评
        for (ProjectItem projectItem : moralGrades.getChildList()) {
            moralGrades.setCurrentGrades(moralGrades.getCurrentGrades().add(projectItem.getCurrentGrades()));
            moralGrades.setEndGrades(moralGrades.getEndGrades().add(projectItem.getEndGrades()));
        }
        projectItemList.add(moralGrades);

        // 智育
        ProjectItem intellectualGrades = new ProjectItem();
        intellectualGrades.setMaxGrades(new BigDecimal(60));
        intellectualGrades.setKey("智育素质测评");
        intellectualGrades.setChildList(getIntellectualData(studentKey, currentTermId));
        // 计算
        for (ProjectItem projectItem : intellectualGrades.getChildList()) {
            intellectualGrades.setCurrentGrades(intellectualGrades.getCurrentGrades().add(projectItem.getCurrentGrades()));
            intellectualGrades.setEndGrades(intellectualGrades.getEndGrades().add(projectItem.getEndGrades()));
        }

        projectItemList.add(intellectualGrades);

        // 体育成绩
        ProjectItem peIntellectualGrades = getPeGrades(studentKey, currentTermId);
        projectItemList.add(peIntellectualGrades);

        // 美育素质评分
        ProjectItem beautyGrades = new ProjectItem();
        beautyGrades.setKey("美育素质评分");
        beautyGrades.setChildList(getBeautyGrades(studentKey, currentTermId));
        beautyGrades.setMaxGrades(new BigDecimal(3));

        // 计算美育素质评分
        for (ProjectItem projectItem : beautyGrades.getChildList()) {
            beautyGrades.setCurrentGrades(beautyGrades.getCurrentGrades().add(projectItem.getCurrentGrades()));
            beautyGrades.setEndGrades(beautyGrades.getEndGrades().add(projectItem.getEndGrades()));
        }
        beautyGrades.setEndGrades(beautyGrades.getCurrentGrades().compareTo(beautyGrades.getMaxGrades()) > 0 ?
                beautyGrades.getMaxGrades() : beautyGrades.getCurrentGrades());
        projectItemList.add(beautyGrades);

        // 劳育素质评分
        ProjectItem laborGrades = new ProjectItem();
        laborGrades.setMaxGrades(new BigDecimal(8));
        laborGrades.setKey("劳育素质评分");
        laborGrades.setChildList(getLaborGrades(studentKey, currentTermId));
        // 计算劳动育素质分
        for (ProjectItem projectItem : laborGrades.getChildList()) {
            laborGrades.setCurrentGrades(laborGrades.getCurrentGrades().add(projectItem.getCurrentGrades()));
            laborGrades.setEndGrades(laborGrades.getEndGrades().add(projectItem.getEndGrades()));
        }
        laborGrades.setEndGrades(laborGrades.getCurrentGrades().compareTo(laborGrades.getMaxGrades()) > 0 ?
                laborGrades.getMaxGrades() : laborGrades.getCurrentGrades());

        projectItemList.add(laborGrades);

        // 互评分
        ProjectItem evaluationGrades = new ProjectItem();
        evaluationGrades.setMaxGrades(new BigDecimal(6));
        evaluationGrades.setKey("互评分");
        evaluationGrades.setChildList(getEvaluationGrades(studentKey, currentTermId));
        // 计算互评分
        for (ProjectItem projectItem : evaluationGrades.getChildList()) {
            evaluationGrades.setCurrentGrades(evaluationGrades.getCurrentGrades().add(projectItem.getCurrentGrades()));
            evaluationGrades.setEndGrades(evaluationGrades.getEndGrades().add(projectItem.getEndGrades()));
        }
        evaluationGrades.setEndGrades(evaluationGrades.getCurrentGrades().compareTo(evaluationGrades.getMaxGrades()) > 0 ? evaluationGrades.getMaxGrades() : evaluationGrades.getCurrentGrades());

        projectItemList.add(evaluationGrades);

        // 扣分
        ProjectItem punishGrades = new ProjectItem();
        punishGrades.setKey("扣分");
        punishGrades.setChildList(getPunishGrades(studentKey, currentTermId));
        // 计算扣分项
        for (ProjectItem projectItem : punishGrades.getChildList()) {
            punishGrades.setCurrentGrades(punishGrades.getCurrentGrades().add(projectItem.getCurrentGrades()));
            punishGrades.setEndGrades(punishGrades.getEndGrades().add(projectItem.getEndGrades()));
        }
        punishGrades.setEndGrades(punishGrades.getCurrentGrades().compareTo(punishGrades.getMaxGrades()) > 0 ? punishGrades.getMaxGrades() : punishGrades.getCurrentGrades());

        projectItemList.add(punishGrades);


        return CommonResult.success(projectItemList);
    }

    /**
     * 查询班级排名表
     *
     * @param classId
     * @return
     */
    @Override
    public CommonResult<List<ClassLevelGetVo>> getLevelByClassId(Long classId) {

        RewardDistribution rewardDistribution = iRewardDistributionService.getOne(new QueryWrapper<RewardDistribution>().lambda()
                .eq(RewardDistribution::getClassId, classId)
                .eq(RewardDistribution::getTermId, termMapper.getCurrentTerm())
                .last("limit 1"));

        int firstReward = 0;
        String firstRewardDesc = "一等奖学金";
        int secondReward = 0;
        String secondRewardDesc = "二等奖学金";
        int thirdReward = 0;
        String thirdRewardDesc = "三等奖学金";

        if (rewardDistribution != null) {
            firstReward = rewardDistribution.getOneNums();
            secondReward = rewardDistribution.getTwoNums();
            thirdReward = rewardDistribution.getThreeNums();
        }

        List<PerStudent> perStudentList = iPerStudentService.list(new QueryWrapper<PerStudent>().lambda()
                .eq(PerStudent::getClassId, classId));


        int allPeople = perStudentList.size();

        // 非实验班 - 考虑智育排名 一等奖学金 前25% 二等奖学金 前40% 三等奖学金 前75%
        int firstMinLevel = (int) (allPeople * 0.25);
        if (firstMinLevel == 0) {
            firstMinLevel = 1;
        }
        int secondMinLevel = (int) (allPeople * 0.4);
        if (secondMinLevel == 0) {
            secondMinLevel = 1;
        }
        int thirdMinLevel = (int) (allPeople * 0.75);
        if (thirdMinLevel == 0) {
            thirdMinLevel = 1;
        }

        List<ClassLevelGetVo> classLevelGetVos = new ArrayList<>();

        for (PerStudent perStudent : perStudentList) {
            ClassLevelGetVo vo = new ClassLevelGetVo();
            List<ProjectItem> projectItemList = getCurrentTermData(perStudent.getStudentKey()).getData();
            for (ProjectItem projectItem : projectItemList) {
                if (projectItem.getKey().equals("德育素质测评")) {
                    vo.setMoralGrades(projectItem.getEndGrades());
                } else if (projectItem.getKey().equals("智育素质测评")) {
                    vo.setIntellectualGrades(projectItem.getEndGrades());
                } else if (projectItem.getKey().equals("美育素质评分")) {
                    vo.setBeautyGrades(projectItem.getEndGrades());
                } else if (projectItem.getKey().equals("劳育素质评分")) {
                    vo.setLaborGrades(projectItem.getEndGrades());
                } else if (projectItem.getKey().equals("体育成绩")) {
                    vo.setPeGrades(projectItem.getEndGrades());
                } else if (projectItem.getKey().equals("互评分")) {
                    vo.setEvaluationGrades(projectItem.getEndGrades());
                } else if (projectItem.getKey().equals("扣分")) {
                    vo.setPunishGrades(projectItem.getEndGrades());
                }
                vo.setStudentKey(perStudent.getStudentKey());
                vo.setStudentName(perStudent.getName());
                vo.setAllGrades(vo.getAllGrades().add(projectItem.getEndGrades()));
            }
            classLevelGetVos.add(vo);
            // 查询是否有不及格科目
            StudyGrades studyGrades = iStudyGradesService.getOne(new QueryWrapper<StudyGrades>().lambda()
                    .eq(StudyGrades::getStudentKey, perStudent.getStudentKey())
                    .eq(StudyGrades::getTermId, termMapper.getCurrentTerm())
                    .last("limit 1"));
            if (studyGrades != null) {
                vo.setIsHasNotPass(studyGrades.getHasNotPass());
                vo.setIsQualification(false);
            } else {
                vo.setIsHasNotPass(false);
            }
            // 查询是否有处分
            int punishment = iPunishmentService.count(new QueryWrapper<Punishment>().lambda()
                    .eq(Punishment::getStudentKey, perStudent.getStudentKey())
                    .eq(Punishment::getTermId, termMapper.getCurrentTerm()));
            vo.setIsPunishment(punishment > 0);
            vo.setIsQualification(punishment <= 0);

        }
        // 按照智育成绩排序
        classLevelGetVos.sort(new Comparator<ClassLevelGetVo>() {
            @Override
            public int compare(ClassLevelGetVo o1, ClassLevelGetVo o2) {
                return o2.getIntellectualGrades().compareTo(o1.getIntellectualGrades());
            }
        });

        int level = 1;
        int lastLevel = 1;
        for (int i = 0; i < classLevelGetVos.size(); i++) {
            if (i != 0) {
                // 如果和上一个成绩相等
                if (classLevelGetVos.get(i).getIntellectualGrades().compareTo(classLevelGetVos.get(i - 1).getIntellectualGrades()) == 0) {
                    classLevelGetVos.get(i).setIntellectualLevel(lastLevel);
                } else {
                    classLevelGetVos.get(i).setIntellectualLevel(level);
                    lastLevel = level;
                }
            } else {
                classLevelGetVos.get(i).setIntellectualLevel(level);
                lastLevel = level;
            }
            level++;
        }

        // 按照德育排序
        classLevelGetVos.sort(new Comparator<ClassLevelGetVo>() {
            @Override
            public int compare(ClassLevelGetVo o1, ClassLevelGetVo o2) {
                return o2.getMoralGrades().compareTo(o1.getMoralGrades());
            }
        });

        level = 1;
        lastLevel = 1;
        for (int i = 0; i < classLevelGetVos.size(); i++) {
            if (i != 0) {
                // 如果和上一个成绩相等
                if (classLevelGetVos.get(i).getMoralGrades().compareTo(classLevelGetVos.get(i - 1).getMoralGrades()) == 0) {
                    classLevelGetVos.get(i).setMoralLevel(lastLevel);
                } else {
                    classLevelGetVos.get(i).setMoralLevel(level);
                    lastLevel = level;
                }
            } else {
                classLevelGetVos.get(i).setMoralLevel(level);
                lastLevel = level;
            }
            level++;
        }


        // 按照体育排序
        classLevelGetVos.sort(new Comparator<ClassLevelGetVo>() {
            @Override
            public int compare(ClassLevelGetVo o1, ClassLevelGetVo o2) {
                return o2.getPeGrades().compareTo(o1.getPeGrades());
            }
        });

        level = 1;
        lastLevel = 1;
        for (int i = 0; i < classLevelGetVos.size(); i++) {
            if (i != 0) {
                // 如果和上一个成绩相等
                if (classLevelGetVos.get(i).getPeGrades().compareTo(classLevelGetVos.get(i - 1).getPeGrades()) == 0) {
                    classLevelGetVos.get(i).setPeLevel(lastLevel);
                } else {
                    classLevelGetVos.get(i).setPeLevel(level);
                    lastLevel = level;
                }
            } else {
                classLevelGetVos.get(i).setPeLevel(level);
                lastLevel = level;
            }
            level++;
        }

        // 按照美育排序
        classLevelGetVos.sort(new Comparator<ClassLevelGetVo>() {
            @Override
            public int compare(ClassLevelGetVo o1, ClassLevelGetVo o2) {
                return o2.getBeautyGrades().compareTo(o1.getBeautyGrades());
            }
        });

        level = 1;
        lastLevel = 1;
        for (int i = 0; i < classLevelGetVos.size(); i++) {
            if (i != 0) {
                // 如果和上一个成绩相等
                if (classLevelGetVos.get(i).getBeautyGrades().compareTo(classLevelGetVos.get(i - 1).getBeautyGrades()) == 0) {
                    classLevelGetVos.get(i).setBeautyLevel(lastLevel);
                } else {
                    classLevelGetVos.get(i).setBeautyLevel(level);
                    lastLevel = level;
                }
            } else {
                classLevelGetVos.get(i).setBeautyLevel(level);
                lastLevel = level;
            }
            level++;
        }

        // 按照劳育排序
        classLevelGetVos.sort(new Comparator<ClassLevelGetVo>() {
            @Override
            public int compare(ClassLevelGetVo o1, ClassLevelGetVo o2) {
                return o2.getLaborGrades().compareTo(o1.getLaborGrades());
            }
        });

        level = 1;
        lastLevel = 1;
        for (int i = 0; i < classLevelGetVos.size(); i++) {
            if (i != 0) {
                // 如果和上一个成绩相等
                if (classLevelGetVos.get(i).getLaborGrades().compareTo(classLevelGetVos.get(i - 1).getLaborGrades()) == 0) {
                    classLevelGetVos.get(i).setLaborLevel(lastLevel);
                } else {
                    classLevelGetVos.get(i).setLaborLevel(level);
                    lastLevel = level;
                }
            } else {
                classLevelGetVos.get(i).setLaborLevel(level);
                lastLevel = level;
            }
            level++;
        }

        // 按照互评分排序
        classLevelGetVos.sort(new Comparator<ClassLevelGetVo>() {
            @Override
            public int compare(ClassLevelGetVo o1, ClassLevelGetVo o2) {
                return o2.getEvaluationGrades().compareTo(o1.getEvaluationGrades());
            }
        });

        level = 1;
        lastLevel = 1;
        for (int i = 0; i < classLevelGetVos.size(); i++) {
            if (i != 0) {
                // 如果和上一个成绩相等
                if (classLevelGetVos.get(i).getEvaluationGrades().compareTo(classLevelGetVos.get(i - 1).getEvaluationGrades()) == 0) {
                    classLevelGetVos.get(i).setEvaluationLevel(lastLevel);
                } else {
                    classLevelGetVos.get(i).setEvaluationLevel(level);
                    lastLevel = level;
                }
            } else {
                classLevelGetVos.get(i).setEvaluationLevel(level);
                lastLevel = level;
            }
            level++;
        }

        // 按照总成绩排序
        classLevelGetVos.sort(new Comparator<ClassLevelGetVo>() {
            @Override
            public int compare(ClassLevelGetVo o1, ClassLevelGetVo o2) {
                return o2.getAllGrades().compareTo(o1.getAllGrades());
            }
        });

        level = 1;
        lastLevel = 1;
        for (int i = 0; i < classLevelGetVos.size(); i++) {
            if (i != 0) {
                // 如果和上一个成绩相等
                if (classLevelGetVos.get(i).getAllGrades().compareTo(classLevelGetVos.get(i - 1).getAllGrades()) == 0) {
                    classLevelGetVos.get(i).setLevel(lastLevel);
                } else {
                    classLevelGetVos.get(i).setLevel(level);
                    lastLevel = level;
                }
            } else {
                classLevelGetVos.get(i).setLevel(level);
                lastLevel = level;
            }
            level++;
        }


        // 查询班级类型
        StuClass stuClass = iStuClassService.getById(classId);
        // 最终返回的数据
        List<ClassLevelGetVo> endClassLevelGetVoList = new ArrayList<>();

        if (stuClass.getIsExperiment()) {
            // 实验班 - 忽略智育排名
            for (int i = 0; i < classLevelGetVos.size(); i++) {
                if (i < firstReward) {
                    classLevelGetVos.get(i).setReward(firstRewardDesc);
                } else if (i < secondReward) {
                    classLevelGetVos.get(i).setReward(secondRewardDesc);
                } else if (i < thirdReward) {
                    classLevelGetVos.get(i).setReward(thirdRewardDesc);
                }
                endClassLevelGetVoList.add(classLevelGetVos.get(i));
            }
        } else {
            // 非实验班 - 考虑智育排名 一等奖学金 前25% 二等奖学金 前40% 三等奖学金 前75%
            // 无及格科目 - 无处分
            int hasFirst = 0;
            int hasSecond = 0;
            int hasThird = 0;
            // 找一等奖
            for (int i = 0; i < classLevelGetVos.size(); i++) {
                if (classLevelGetVos.get(i).getIntellectualLevel() <= firstMinLevel
                        && hasFirst < firstReward
                        && classLevelGetVos.get(i).getIsQualification()
                ) {
                    classLevelGetVos.get(i).setReward(firstRewardDesc);
                    hasFirst++;
                    endClassLevelGetVoList.add(classLevelGetVos.get(i));
                }
            }
            // 找二等奖
            for (int i = 0; i < classLevelGetVos.size(); i++) {
                if (classLevelGetVos.get(i).getIntellectualLevel() <= secondMinLevel
                        && hasSecond < secondReward
                        && classLevelGetVos.get(i).getIsQualification()
                        && classLevelGetVos.get(i).getReward().equals("")
                ) {
                    classLevelGetVos.get(i).setReward(secondRewardDesc);
                    hasSecond++;
                    endClassLevelGetVoList.add(classLevelGetVos.get(i));
                }
            }
            // 找三等奖
            for (int i = 0; i < classLevelGetVos.size(); i++) {
                if (classLevelGetVos.get(i).getIntellectualLevel() <= thirdMinLevel
                        && hasThird < thirdReward
                        && classLevelGetVos.get(i).getIsQualification()
                        && classLevelGetVos.get(i).getReward().equals("")
                ) {
                    classLevelGetVos.get(i).setReward(thirdRewardDesc);
                    hasThird++;
                    endClassLevelGetVoList.add(classLevelGetVos.get(i));
                }
            }

            // 添加没有奖的
            for (int i = 0; i < classLevelGetVos.size(); i++) {
                if (classLevelGetVos.get(i).getReward().equals("")) {
                    endClassLevelGetVoList.add(classLevelGetVos.get(i));
                }
            }
        }

        return CommonResult.success(endClassLevelGetVoList);
    }

    /**
     * 查询扣分项
     *
     * @param studentKey
     * @param currentTermId
     * @return
     */
    private List<ProjectItem> getPunishGrades(String studentKey, Long currentTermId) {
        List<ProjectItem> projectItemList = new ArrayList<>();
        // 违反四项基本原则
        List<FourPrinciple> fourPrincipleList = iFourPrincipleService.list(new QueryWrapper<FourPrinciple>().lambda()
                .eq(FourPrinciple::getStudentKey, studentKey)
                .eq(FourPrinciple::getTermId, currentTermId));

        if (fourPrincipleList.size() > 0) {
            ProjectItem item = new ProjectItem();
            item.setKey("违反四项基本原则");
            item.setChildList(new ArrayList<>());
            for (FourPrinciple fourPrinciple : fourPrincipleList) {
                ProjectItem projectItem = new ProjectItem();
                projectItem.setEndGrades(fourPrinciple.getFraction().negate());
                projectItem.setCurrentGrades(fourPrinciple.getFraction().negate());
                projectItem.setKey(fourPrinciple.getReason());
                item.getChildList().add(projectItem);
            }

            // 计算
            for (ProjectItem projectItem : item.getChildList()) {
                item.setCurrentGrades(item.getCurrentGrades().add(projectItem.getCurrentGrades()));
            }
            item.setEndGrades(item.getCurrentGrades());

            projectItemList.add(item);
        }

        // 处分
        List<Punishment> punishmentList = iPunishmentService.list(new QueryWrapper<Punishment>().lambda()
                .eq(Punishment::getStudentKey, studentKey)
                .eq(Punishment::getTermId, currentTermId));

        if (punishmentList.size() > 0) {
            ProjectItem item = new ProjectItem();
            item.setKey("处分");
            item.setChildList(new ArrayList<>());
            for (Punishment punishment : punishmentList) {
                ProjectItem projectItem = new ProjectItem();
                projectItem.setEndGrades(PunishmentType.getGradesByCode(punishment.getLevel()));
                projectItem.setCurrentGrades(PunishmentType.getGradesByCode(punishment.getLevel()));
                projectItem.setKey(PunishmentType.getNameByCode(punishment.getLevel()));
                item.getChildList().add(projectItem);
            }

            // 计算
            for (ProjectItem projectItem : item.getChildList()) {
                item.setCurrentGrades(item.getCurrentGrades().add(projectItem.getCurrentGrades()));
            }
            item.setEndGrades(item.getCurrentGrades());

            projectItemList.add(item);
        }

        // 旷课
        AbsentClass absentClass = iAbsentClassService.getOne(new QueryWrapper<AbsentClass>().lambda()
                .eq(AbsentClass::getStudentKey, studentKey)
                .eq(AbsentClass::getTermId, currentTermId).last("limit 1"));

        if (absentClass != null) {
            ProjectItem absentClassProject = new ProjectItem();
            absentClassProject.setKey("旷课");
            absentClassProject.setValue(absentClass.getNums() + "节");
            absentClassProject.setCurrentGrades(new BigDecimal(absentClass.getNums()).multiply(new BigDecimal("0.5")).negate());
            absentClassProject.setEndGrades(new BigDecimal(absentClass.getNums()).multiply(new BigDecimal("0.5")).negate());
            projectItemList.add(absentClassProject);
        }

        // 缺席班级活动
        List<AbsentActivities> activitiesList = iAbsentActivitiesService.list(new QueryWrapper<AbsentActivities>().lambda()
                .eq(AbsentActivities::getStudentKey, studentKey)
                .eq(AbsentActivities::getTermId, currentTermId));

        if (activitiesList.size() > 0) {
            ProjectItem projectItem = new ProjectItem();
            projectItem.setKey("班级活动缺席");
            projectItem.setChildList(new ArrayList<>());
            for (AbsentActivities absentActivities : activitiesList) {
                ProjectItem item = new ProjectItem();
                item.setKey(absentActivities.getTitle() + "-" + DateUtil.format(absentActivities.getDoTime(), "yyyy-MM-dd"));
                item.setCurrentGrades(new BigDecimal(1).negate());
                item.setEndGrades(new BigDecimal(1).negate());
                item.setMaxGrades(new BigDecimal(1).negate());
                projectItem.getChildList().add(item);
            }
            // 计算
            for (ProjectItem item : projectItem.getChildList()) {
                projectItem.setCurrentGrades(projectItem.getCurrentGrades().add(item.getCurrentGrades()));
                projectItem.setEndGrades(projectItem.getEndGrades().add(item.getEndGrades()));
            }
            projectItemList.add(projectItem);
        }
        return projectItemList;
    }

    /**
     * 查询互评分
     *
     * @param studentKey
     * @param currentTermId
     * @return
     */
    private List<ProjectItem> getEvaluationGrades(String studentKey, Long currentTermId) {

        List<ProjectItem> projectItemList = new ArrayList<>();

        // 班级考核分
        Long classId = perStudentMapper.getClassIdByStudentKey(studentKey);
        ClassLevel classLevel = iClassLevelService.getOne(new QueryWrapper<ClassLevel>().lambda()
                .eq(ClassLevel::getClassId, classId)
                .eq(ClassLevel::getTermId, currentTermId).last("limit 1"));

        if (classLevel != null) {
            ProjectItem item = new ProjectItem();
            item.setKey("班级考核分");
            item.setMaxGrades(new BigDecimal(3));
            if (classLevel.getLevel().equals(10)) {
                item.setValue("A等");
                item.setEndGrades(new BigDecimal(3));
                item.setCurrentGrades(new BigDecimal(3));
            } else if (classLevel.getLevel().equals(20)) {
                item.setValue("B等");
                item.setEndGrades(new BigDecimal("2.5"));
                item.setCurrentGrades(new BigDecimal("2.5"));
            } else {
                item.setValue("C等");
                item.setEndGrades(new BigDecimal(0));
                item.setCurrentGrades(new BigDecimal(0));
            }
            projectItemList.add(item);
        }

        // 班级评价分
        ClassFraction classFraction = iClassFractionService.getOne(new QueryWrapper<ClassFraction>().lambda()
                .eq(ClassFraction::getStudentKey, studentKey)
                .eq(ClassFraction::getTermId, currentTermId)
                .last("limit 1"));
        if (classFraction != null) {
            ProjectItem item = new ProjectItem();
            item.setKey("班级评价分");
            item.setMaxGrades(new BigDecimal(3));
            item.setChildList(new ArrayList<>());

            ProjectItem itemTeacher = new ProjectItem();
            itemTeacher.setKey("老师评分");
            itemTeacher.setMaxGrades(new BigDecimal(2));
            itemTeacher.setEndGrades(classFraction.getTeacherFraction());
            itemTeacher.setCurrentGrades(classFraction.getTeacherFraction());

            ProjectItem itemGroup = new ProjectItem();
            itemGroup.setKey("测评小组评分");
            itemGroup.setMaxGrades(new BigDecimal(1));
            itemGroup.setEndGrades(classFraction.getGroupFraction());
            itemGroup.setCurrentGrades(classFraction.getGroupFraction());

            item.getChildList().add(itemTeacher);
            item.getChildList().add(itemGroup);

            item.setEndGrades(itemGroup.getEndGrades().add(itemTeacher.getEndGrades()));
            item.setCurrentGrades(itemGroup.getEndGrades().add(itemTeacher.getEndGrades()));

            projectItemList.add(item);
        }

        return projectItemList;
    }

    /**
     * 查询劳育素质评分
     *
     * @param studentKey
     * @param currentTermId
     * @return
     */
    private List<ProjectItem> getLaborGrades(String studentKey, Long currentTermId) {

        List<ProjectItem> projectItemList = new ArrayList<>();

        // 实习成绩
        PracticeGrades practiceGrades = iPracticeGradesService.getOne(new QueryWrapper<PracticeGrades>().lambda()
                .eq(PracticeGrades::getStudentKey, studentKey)
                .eq(PracticeGrades::getTermId, currentTermId)
                .last("limit 1"));
        ProjectItem projectItemPractice = new ProjectItem();
        projectItemPractice.setKey("实习成绩");
        projectItemPractice.setMaxGrades(new BigDecimal(3));
        projectItemList.add(projectItemPractice);
        if (practiceGrades != null) {
            if (practiceGrades.getGrades().compareTo(new BigDecimal(90)) >= 0) {
                projectItemPractice.setCurrentGrades(new BigDecimal(3));
                projectItemPractice.setEndGrades(new BigDecimal(3));
            } else if (practiceGrades.getGrades().compareTo(new BigDecimal(85)) >= 0) {
                projectItemPractice.setCurrentGrades(new BigDecimal(2));
                projectItemPractice.setEndGrades(new BigDecimal(2));
            } else if (practiceGrades.getGrades().compareTo(new BigDecimal(75)) >= 0) {
                projectItemPractice.setCurrentGrades(new BigDecimal(1));
                projectItemPractice.setEndGrades(new BigDecimal(1));
            } else {
                projectItemPractice.setCurrentGrades(new BigDecimal(0));
                projectItemPractice.setEndGrades(new BigDecimal(0));
            }
            projectItemPractice.setValue(practiceGrades.getGrades());
        }

        // 寝室卫生
        ProjectItem healthProject = new ProjectItem();
        healthProject.setKey("寝室");
        healthProject.setMaxGrades(new BigDecimal(2));
        healthProject.setChildList(getHealthProject(studentKey, currentTermId));
        for (ProjectItem projectItem : healthProject.getChildList()) {
            healthProject.setCurrentGrades(healthProject.getCurrentGrades().add(projectItem.getCurrentGrades()));
        }
        healthProject.setEndGrades(healthProject.getCurrentGrades().compareTo(healthProject.getMaxGrades()) > 0 ?
                healthProject.getMaxGrades() : healthProject.getCurrentGrades());
        projectItemList.add(healthProject);

        // 公益事业
        ProjectItem volunteerProject = new ProjectItem();
        volunteerProject.setKey("公益事业与志愿服务");
        volunteerProject.setMaxGrades(new BigDecimal(1));
        volunteerProject.setChildList(getVolunteerProject(studentKey, currentTermId));
        for (ProjectItem projectItem : volunteerProject.getChildList()) {
            volunteerProject.setCurrentGrades(volunteerProject.getCurrentGrades().add(projectItem.getCurrentGrades()));
        }
        volunteerProject.setEndGrades(volunteerProject.getCurrentGrades().compareTo(volunteerProject.getMaxGrades()) > 0 ?
                volunteerProject.getMaxGrades() : volunteerProject.getCurrentGrades());
        projectItemList.add(volunteerProject);

        // 学科竞赛
        ProjectItem contestProject = new ProjectItem();
        contestProject.setMaxGrades(new BigDecimal(2));
        contestProject.setKey("学科技能竞赛");
        contestProject.setChildList(new ArrayList<>());
        List<CourseContests> courseContestsList = iCourseContestsService.list(new QueryWrapper<CourseContests>().lambda()
                .eq(CourseContests::getStudentKey, studentKey)
                .eq(CourseContests::getTermId, currentTermId));
        if (courseContestsList.size() > 0) {
            for (CourseContests courseContests : courseContestsList) {
                ProjectItem item = new ProjectItem();
                item.setKey(courseContests.getTitle());
                item.setMaxGrades(new BigDecimal(2));
                item.setValue(CourseContestsType.getNameByCode(courseContests.getType()));
                item.setEndGrades(CourseContestsType.getGradesByCode(courseContests.getType()));
                item.setCurrentGrades(CourseContestsType.getGradesByCode(courseContests.getType()));
                contestProject.getChildList().add(item);
            }
        }
        // 计算学科竞赛
        for (ProjectItem projectItem : contestProject.getChildList()) {
            contestProject.setCurrentGrades(contestProject.getCurrentGrades().add(projectItem.getCurrentGrades()));
        }
        contestProject.setEndGrades(contestProject.getCurrentGrades().compareTo(contestProject.getMaxGrades()) > 0 ?
                contestProject.getMaxGrades() : contestProject.getCurrentGrades());
        projectItemList.add(contestProject);

        return projectItemList;
    }

    /**
     * 公益事业与志愿服务
     *
     * @param studentKey
     * @param currentTermId
     * @return
     */
    private List<ProjectItem> getVolunteerProject(String studentKey, Long currentTermId) {
        List<ProjectItem> projectItemList = new ArrayList<>();
        // 志愿者服务小时数
        Volunteer volunteer = iVolunteerService.getOne(new QueryWrapper<Volunteer>().lambda()
                .eq(Volunteer::getTermId, currentTermId)
                .eq(Volunteer::getStudentKey, studentKey).last("limit 1"));

        if (volunteer != null) {
            ProjectItem item = new ProjectItem();
            item.setKey("志愿者小时数");
            item.setValue(volunteer.getNums());
            item.setMaxGrades(new BigDecimal("0.5"));
            if (volunteer.getNums().compareTo(new BigDecimal("20")) >= 0) {
                item.setCurrentGrades(new BigDecimal("0.5"));
                item.setEndGrades(new BigDecimal("0.5"));
            }
            projectItemList.add(item);
        }

        // 星级志愿者
        VolunteerStar volunteerStar = iVolunteerStarService.getOne(new QueryWrapper<VolunteerStar>().lambda()
                .eq(VolunteerStar::getTermId, currentTermId)
                .eq(VolunteerStar::getStudentKey, studentKey)
                .last("limit 1"));

        if (volunteerStar != null) {
            ProjectItem item = new ProjectItem();
            item.setKey("星级志愿者");
            item.setMaxGrades(new BigDecimal("0.5"));
            item.setValue(VolunteerStartType.getNameByCode(volunteerStar.getStar()));
            item.setEndGrades(VolunteerStartType.getGradesByCode(volunteerStar.getStar()));
            item.setCurrentGrades(VolunteerStartType.getGradesByCode(volunteerStar.getStar()));
            projectItemList.add(item);
        }

        return projectItemList;
    }

    /**
     * 查询寝室卫生子集
     *
     * @param studentKey
     * @param currentTermId
     * @return
     */
    private List<ProjectItem> getHealthProject(String studentKey, Long currentTermId) {

        List<ProjectItem> projectItemList = new ArrayList<>();

        // 寝室卫生等级
        BedroomLevel bedroomLevel = iBedroomLevelService.getOne(new QueryWrapper<BedroomLevel>().lambda()
                .eq(BedroomLevel::getTermId, currentTermId)
                .eq(BedroomLevel::getStudentKey, studentKey).last("limit 1"));

        if (bedroomLevel != null) {
            ProjectItem item = new ProjectItem();
            item.setMaxGrades(new BigDecimal("1.5"));
            item.setKey(BedroomLevelType.getNameByCode(bedroomLevel.getLevel()));
            item.setEndGrades(BedroomLevelType.getGradesByCode(bedroomLevel.getLevel()));
            item.setCurrentGrades(BedroomLevelType.getGradesByCode(bedroomLevel.getLevel()));

            // 总评为C不计分
            if (bedroomLevel.getLevel().equals(com.teacher.pojo.enums.BedroomLevelType.C.getCode())) {
                item.setCurrentGrades(new BigDecimal(0));
                item.setEndGrades(new BigDecimal(0));
                return projectItemList;
            }
            projectItemList.add(item);
        }

        // 寝室荣誉
        BedroomGlory bedroomGlory = iBedroomGloryService.getOne(new QueryWrapper<BedroomGlory>().lambda()
                .eq(BedroomGlory::getStudentKey, studentKey)
                .eq(BedroomGlory::getTermId, currentTermId).last("limit 1"));
        if (bedroomGlory != null) {
            ProjectItem item = new ProjectItem();
            item.setMaxGrades(new BigDecimal("0.5"));
            item.setKey(bedroomGlory.getDescription());
            item.setEndGrades(new BigDecimal("0.5"));
            item.setCurrentGrades(new BigDecimal("0.5"));
            projectItemList.add(item);
        }

        return projectItemList;
    }

    /**
     * 查询美育素质评分
     *
     * @param studentKey
     * @param currentTermId
     * @return
     */
    private List<ProjectItem> getBeautyGrades(String studentKey, Long currentTermId) {
        List<ProjectItem> projectItemList = new ArrayList<>();

        // 美育基本分
        ProjectItem basicProject = new ProjectItem();
        basicProject.setKey("美育基本分");
        basicProject.setChildList(new ArrayList<>());
        basicProject.setMaxGrades(new BigDecimal(30));
        AestheticEducationBasic aestheticEducationBasic = iAestheticEducationBasicService.getOne(new QueryWrapper<AestheticEducationBasic>().lambda()
                .eq(AestheticEducationBasic::getStudentKey, studentKey)
                .eq(AestheticEducationBasic::getTermId, currentTermId)
                .last("limit 1"));
        if (aestheticEducationBasic != null) {
            ProjectItem projectItem1 = new ProjectItem();
            projectItem1.setKey("看一场红色电影");
            if (aestheticEducationBasic.getSeeMove()) {
                projectItem1.setEndGrades(new BigDecimal(10));
                projectItem1.setCurrentGrades(new BigDecimal(10));
                projectItem1.setMaxGrades(new BigDecimal(10));
            }

            ProjectItem projectItem2 = new ProjectItem();
            projectItem2.setKey("参加一次院级以上或个人文艺活动");
            if (aestheticEducationBasic.getDoActivity()) {
                projectItem2.setEndGrades(new BigDecimal(10));
                projectItem2.setCurrentGrades(new BigDecimal(10));
                projectItem2.setMaxGrades(new BigDecimal(10));
            }

            ProjectItem projectItem3 = new ProjectItem();
            projectItem3.setKey("艺术展示");
            if (aestheticEducationBasic.getArtShow()) {
                projectItem3.setEndGrades(new BigDecimal(10));
                projectItem3.setCurrentGrades(new BigDecimal(10));
                projectItem3.setMaxGrades(new BigDecimal(10));
            }
            basicProject.getChildList().add(projectItem1);
            basicProject.getChildList().add(projectItem2);
            basicProject.getChildList().add(projectItem3);

            // 计算
            for (ProjectItem projectItem : basicProject.getChildList()) {
                basicProject.setCurrentGrades(basicProject.getCurrentGrades().add(projectItem.getCurrentGrades()));
            }
            basicProject.setEndGrades(basicProject.getCurrentGrades());
            basicProject.setMaxGrades(new BigDecimal(30));
            basicProject.setEndGrades(basicProject.getEndGrades().multiply(new BigDecimal("0.03")));
            basicProject.setValue("总分乘0.03");
        }

        // 文艺活动分
        ProjectItem activitiesProject = new ProjectItem();
        activitiesProject.setKey("文艺活动分");
        activitiesProject.setMaxGrades(new BigDecimal(30));
        activitiesProject.setChildList(getActivitiesProject(studentKey, currentTermId));
        // 计算文艺活动分
        for (ProjectItem projectItem : activitiesProject.getChildList()) {
            activitiesProject.setCurrentGrades(activitiesProject.getCurrentGrades().add(projectItem.getEndGrades()));
        }
        activitiesProject.setEndGrades(activitiesProject.getCurrentGrades().compareTo(activitiesProject.getMaxGrades()) > 0 ?
                activitiesProject.getMaxGrades() : activitiesProject.getCurrentGrades());
        activitiesProject.setEndGrades(activitiesProject.getEndGrades().multiply(new BigDecimal("0.03")));
        activitiesProject.setValue("总分乘0.03");

        // 日常行为规范分
        ProjectItem behaviorProject = new ProjectItem();
        behaviorProject.setKey("日常行为规范");
        behaviorProject.setMaxGrades(new BigDecimal(40));
        behaviorProject.setCurrentGrades(new BigDecimal(40));
        behaviorProject.setChildList(getBehaviorProject(studentKey, currentTermId));
        // 计算日常行为规范分
        if (behaviorProject.getChildList().size() >= 8) {
            behaviorProject.setCurrentGrades(behaviorProject.getCurrentGrades().subtract(new BigDecimal(5).multiply(new BigDecimal(behaviorProject.getChildList().size()))));
            behaviorProject.setEndGrades(new BigDecimal(0));
        } else {
            behaviorProject.setCurrentGrades(behaviorProject.getCurrentGrades().subtract(new BigDecimal(5).multiply(new BigDecimal(behaviorProject.getChildList().size()))));
            behaviorProject.setEndGrades(behaviorProject.getCurrentGrades());
        }

        behaviorProject.setEndGrades(behaviorProject.getEndGrades().multiply(new BigDecimal("0.03")));
        behaviorProject.setValue("总分乘0.03");

        projectItemList.add(behaviorProject);
        projectItemList.add(basicProject);
        projectItemList.add(activitiesProject);


        return projectItemList;
    }

    /**
     * 日常行为规范分
     *
     * @param studentKey
     * @param currentTermId
     * @return
     */
    private List<ProjectItem> getBehaviorProject(String studentKey, Long currentTermId) {
        List<ProjectItem> projectItemList = new ArrayList<>();
        List<Behavior> behaviorList = iBehaviorService.list(new QueryWrapper<Behavior>().lambda()
                .eq(Behavior::getStudentKey, studentKey)
                .eq(Behavior::getTermId, currentTermId));
        if (behaviorList.size() <= 0) {
            return new ArrayList<>();
        }

        for (Behavior behavior : behaviorList) {
            ProjectItem projectItem = new ProjectItem();
            projectItem.setKey(behavior.getReason());
            projectItem.setCurrentGrades(new BigDecimal(-5));
            projectItem.setEndGrades(new BigDecimal(-5));
            projectItemList.add(projectItem);
        }

        return projectItemList;
    }

    /**
     * 文艺活动分
     *
     * @param studentKey
     * @param currentTermId
     * @return
     */
    private List<ProjectItem> getActivitiesProject(String studentKey, Long currentTermId) {

        List<ProjectItem> projectItemList = new ArrayList<>();

        List<CulturalActivitiesReward> activitiesRewardList = iCulturalActivitiesRewardService.list(new QueryWrapper<CulturalActivitiesReward>().lambda()
                .eq(CulturalActivitiesReward::getStudentKey, studentKey)
                .eq(CulturalActivitiesReward::getTermId, currentTermId));

        if (activitiesRewardList.size() <= 0) {
            return projectItemList;
        }

        for (CulturalActivitiesReward culturalActivitiesReward : activitiesRewardList) {
            ProjectItem projectItem = new ProjectItem();
            projectItem.setMaxGrades(CulturalActivitiesRewardType.getGradesByCode(culturalActivitiesReward.getType()));
            projectItem.setKey(culturalActivitiesReward.getTitle());
            projectItem.setValue(CulturalActivitiesRewardType.getNameByCode(culturalActivitiesReward.getType()));
            projectItem.setCurrentGrades(culturalActivitiesReward.getApplyFraction());
            projectItem.setEndGrades(culturalActivitiesReward.getApplyFraction().compareTo(projectItem.getMaxGrades()) > 0 ?
                    projectItem.getMaxGrades() : culturalActivitiesReward.getApplyFraction());
            projectItemList.add(projectItem);
        }

        return projectItemList;
    }

    /**
     * 体育成绩
     *
     * @param studentKey
     * @param currentTermId
     * @return
     */
    private ProjectItem getPeGrades(String studentKey, Long currentTermId) {
        ProjectItem projectItem = new ProjectItem();
        projectItem.setKey("体育素质评分");
        projectItem.setMaxGrades(new BigDecimal(10));
        projectItem.setChildList(new ArrayList<>());
        Boolean isPe = perStudentMapper.isPe(studentKey);
        if (isPe) {
            // 体育专业
            PhysicalEducationMajor physicalEducationMajor = iPhysicalEducationMajorService.getOne(new QueryWrapper<PhysicalEducationMajor>().lambda()
                    .eq(PhysicalEducationMajor::getStudentKey, studentKey)
                    .eq(PhysicalEducationMajor::getTermId, currentTermId).last("limit 1"));
            if (physicalEducationMajor != null) {
                ProjectItem projectItem1 = new ProjectItem();
                projectItem1.setKey("体育基本分");
                projectItem1.setCurrentGrades(physicalEducationMajor.getBasicGrades());
                projectItem1.setMaxGrades(new BigDecimal(7));
                projectItem1.setEndGrades(projectItem1.getCurrentGrades().compareTo(projectItem1.getMaxGrades()) > 0 ?
                        projectItem1.getMaxGrades() : projectItem1.getCurrentGrades());

                ProjectItem projectItem2 = new ProjectItem();
                projectItem2.setKey("体育竞赛服务");
                projectItem2.setCurrentGrades(physicalEducationMajor.getServiceGrades());
                projectItem2.setMaxGrades(new BigDecimal(3));
                projectItem2.setEndGrades(projectItem2.getCurrentGrades().compareTo(projectItem2.getMaxGrades()) > 0 ?
                        projectItem2.getMaxGrades() : projectItem2.getCurrentGrades());

                projectItem.getChildList().add(projectItem1);
                projectItem.getChildList().add(projectItem2);
            }
        } else {
            // 非体育专业
            PhysicalEducationNormal physicalEducationNormal = iPhysicalEducationNormalService.getOne(new QueryWrapper<PhysicalEducationNormal>().lambda()
                    .eq(PhysicalEducationNormal::getStudentKey, studentKey)
                    .eq(PhysicalEducationNormal::getTermId, currentTermId).last("limit 1"));
            if (physicalEducationNormal != null) {
                ProjectItem projectItem1 = new ProjectItem();
                projectItem1.setKey("体育课成绩");
                projectItem1.setCurrentGrades(physicalEducationNormal.getClassGrades());
                projectItem1.setMaxGrades(new BigDecimal(4));
                projectItem1.setEndGrades(projectItem1.getCurrentGrades().compareTo(projectItem1.getMaxGrades()) > 0 ?
                        projectItem1.getMaxGrades() : projectItem1.getCurrentGrades());

                ProjectItem projectItem2 = new ProjectItem();
                projectItem2.setKey("体测成绩");
                projectItem2.setCurrentGrades(physicalEducationNormal.getTestGrades());
                projectItem2.setMaxGrades(new BigDecimal(4));
                projectItem2.setEndGrades(projectItem2.getCurrentGrades().compareTo(projectItem2.getMaxGrades()) > 0 ?
                        projectItem2.getMaxGrades() : projectItem2.getCurrentGrades());


                ProjectItem projectItem3 = new ProjectItem();
                projectItem3.setKey("课外体育活动成绩");
                projectItem3.setCurrentGrades(physicalEducationNormal.getActivityGrades());
                projectItem3.setMaxGrades(new BigDecimal(2));
                projectItem3.setEndGrades(projectItem3.getCurrentGrades().compareTo(projectItem3.getMaxGrades()) > 0 ?
                        projectItem3.getMaxGrades() : projectItem3.getCurrentGrades());

                projectItem.getChildList().add(projectItem1);
                projectItem.getChildList().add(projectItem2);
                projectItem.getChildList().add(projectItem3);
            }
        }

        for (ProjectItem item : projectItem.getChildList()) {
            projectItem.setCurrentGrades(projectItem.getCurrentGrades().add(item.getCurrentGrades()));
        }
        projectItem.setEndGrades(projectItem.getCurrentGrades().compareTo(projectItem.getMaxGrades()) > 0 ?
                projectItem.getMaxGrades() : projectItem.getCurrentGrades());

        return projectItem;
    }

    /**
     * 查询智育素质测评
     *
     * @param studentKey
     * @param currentTermId
     * @return
     */
    private List<ProjectItem> getIntellectualData(String studentKey, Long currentTermId) {
        List<ProjectItem> projectItemList = new ArrayList<>();
        // 学业成绩
        ProjectItem gradesProject = getGradesProject(studentKey, currentTermId);
        projectItemList.add(gradesProject);

        // 证书分
        ProjectItem certificateProject = getCertificateProject(studentKey, currentTermId);
        projectItemList.add(certificateProject);

        // 创新创业分
        ProjectItem createProject = getCreateProject(studentKey, currentTermId);
        projectItemList.add(createProject);

        return projectItemList;
    }

    /**
     * 创新创业分
     *
     * @param studentKey
     * @param currentTermId
     * @return
     */
    private ProjectItem getCreateProject(String studentKey, Long currentTermId) {
        ProjectItem projectItem = new ProjectItem();
        projectItem.setKey("创新创业分");
        projectItem.setMaxGrades(new BigDecimal("0.5"));
        projectItem.setChildList(new ArrayList<>());
        List<InnovativeUndertaking> undertakingList = iInnovativeUndertakingService.list(new QueryWrapper<InnovativeUndertaking>().lambda()
                .eq(InnovativeUndertaking::getStudentKey, studentKey)
                .eq(InnovativeUndertaking::getTermId, currentTermId));

        for (InnovativeUndertaking innovativeUndertaking : undertakingList) {
            ProjectItem item = new ProjectItem();
            item.setKey(InnovativeUndertakingType.getNameByCode(innovativeUndertaking.getType()));
            item.setEndGrades(InnovativeUndertakingType.getGradesByCode(innovativeUndertaking.getType()));
            item.setCurrentGrades(InnovativeUndertakingType.getGradesByCode(innovativeUndertaking.getType()));
            item.setMaxGrades(InnovativeUndertakingType.getGradesByCode(innovativeUndertaking.getType()));
            projectItem.getChildList().add(item);
        }

        for (ProjectItem item : projectItem.getChildList()) {
            projectItem.setCurrentGrades(projectItem.getCurrentGrades().add(item.getEndGrades()));
        }

        projectItem.setEndGrades(projectItem.getCurrentGrades().compareTo(projectItem.getMaxGrades()) > 0 ?
                projectItem.getMaxGrades() : projectItem.getCurrentGrades());

        return projectItem;
    }

    /**
     * 查询证书分
     *
     * @param studentKey
     * @param currentTermId
     * @return
     */
    private ProjectItem getCertificateProject(String studentKey, Long currentTermId) {
        ProjectItem projectItem = new ProjectItem();
        projectItem.setKey("证书分");
        projectItem.setMaxGrades(new BigDecimal(5));
        projectItem.setChildList(new ArrayList<>());
        // 永久分
        ProjectItem foreverItem = new ProjectItem();
        foreverItem.setKey("每学期累加分");
        foreverItem.setChildList(new ArrayList<>());
        foreverItem.setMaxGrades(new BigDecimal(5));
        List<Certificate> foreverList = iCertificateService.list(new QueryWrapper<Certificate>().lambda()
                .eq(Certificate::getStudentKey, studentKey)
                .eq(Certificate::getIsForever, true));
        ProjectItem computer = new ProjectItem();
        computer.setKey("计算机证书");
        computer.setMaxGrades(new BigDecimal(5));

        ProjectItem english = new ProjectItem();
        english.setKey("英语等级证书");
        english.setMaxGrades(new BigDecimal(5));

        ProjectItem speak = new ProjectItem();
        speak.setKey("普通话证书");
        speak.setMaxGrades(new BigDecimal(5));

        ProjectItem teacher = new ProjectItem();
        teacher.setKey("教师资格证书");
        teacher.setMaxGrades(new BigDecimal(5));

        foreverItem.getChildList().add(computer);
        foreverItem.getChildList().add(english);
        foreverItem.getChildList().add(speak);
        foreverItem.getChildList().add(teacher);
        for (Certificate certificate : foreverList) {
            if (certificate.getType().equals(CertificateType.COMPUTER.getCode())) {
                // 计算机证书
                BigDecimal grades = ComputerType.getGradesByCode(certificate.getLevel());
                if (grades.compareTo(computer.getEndGrades()) > 0) {
                    computer.setCurrentGrades(grades);
                    computer.setEndGrades(grades);
                    computer.setValue(ComputerType.getNameByCode(certificate.getLevel()));
                }
            }
            if (certificate.getType().equals(CertificateType.ENGLISH.getCode())) {
                // 英语等级证书
                BigDecimal grades = EnglishType.getGradesByCode(certificate.getLevel());
                if (grades.compareTo(english.getEndGrades()) > 0) {
                    english.setCurrentGrades(grades);
                    english.setEndGrades(grades);
                    english.setValue(EnglishType.getNameByCode(certificate.getLevel()));
                }
            }
            if (certificate.getType().equals(CertificateType.SPEAKING.getCode())) {
                // 普通话证书
                BigDecimal grades = SpeakType.getGradesByCode(certificate.getLevel());
                if (grades.compareTo(speak.getEndGrades()) > 0) {
                    speak.setCurrentGrades(grades);
                    speak.setEndGrades(grades);
                    speak.setValue(SpeakType.getNameByCode(certificate.getLevel()));
                }
            }
            if (certificate.getType().equals(CertificateType.TEACHER.getCode())) {
                // 教师资格证书
                BigDecimal grades = TeacherType.getGradesByCode(certificate.getLevel());
                if (grades.compareTo(teacher.getEndGrades()) > 0) {
                    teacher.setCurrentGrades(grades);
                    teacher.setEndGrades(grades);
                    teacher.setValue(TeacherType.getNameByCode(certificate.getLevel()));
                }
            }
        }

        // 计算
        for (ProjectItem item : foreverItem.getChildList()) {
            foreverItem.setEndGrades(foreverItem.getEndGrades().add(item.getEndGrades()));
            foreverItem.setCurrentGrades(foreverItem.getEndGrades());
        }

        // 本学期分
        List<Certificate> notForeverList = iCertificateService.list(new QueryWrapper<Certificate>().lambda()
                .eq(Certificate::getStudentKey, studentKey)
                .eq(Certificate::getTermId, currentTermId)
                .eq(Certificate::getIsForever, false));
        ProjectItem notForeverItem = new ProjectItem();
        notForeverItem.setKey("本学期加分");
        notForeverItem.setChildList(new ArrayList<>());
        notForeverItem.setMaxGrades(new BigDecimal(5));
        for (Certificate certificate : notForeverList) {
            ProjectItem item = new ProjectItem();
            item.setKey(certificate.getTitle());
            item.setEndGrades(certificate.getApplyFraction());
            item.setCurrentGrades(certificate.getApplyFraction());
            item.setMaxGrades(new BigDecimal(5));
            notForeverItem.getChildList().add(item);
        }

        // 计算
        for (ProjectItem item : notForeverItem.getChildList()) {
            notForeverItem.setEndGrades(notForeverItem.getEndGrades().add(item.getEndGrades()));
            notForeverItem.setCurrentGrades(notForeverItem.getEndGrades());
        }

        projectItem.getChildList().add(foreverItem);
        projectItem.getChildList().add(notForeverItem);

        // 总的计算
        for (ProjectItem item : projectItem.getChildList()) {
            projectItem.setCurrentGrades(item.getCurrentGrades().add(projectItem.getCurrentGrades()));
        }
        projectItem.setEndGrades(projectItem.getCurrentGrades().compareTo(projectItem.getMaxGrades()) > 0 ?
                projectItem.getMaxGrades() : projectItem.getCurrentGrades());

        return projectItem;
    }

    /**
     * 查询学业成绩
     *
     * @param studentKey
     * @param currentTermId
     * @return
     */
    private ProjectItem getGradesProject(String studentKey, Long currentTermId) {
        ProjectItem projectItem = new ProjectItem();
        projectItem.setKey("学业成绩");
        StudyGrades studyGrades = iStudyGradesService.getOne(new QueryWrapper<StudyGrades>().lambda()
                .eq(StudyGrades::getStudentKey, studentKey)
                .eq(StudyGrades::getTermId, currentTermId).last("limit 1"));
        projectItem.setMaxGrades(new BigDecimal(55));
        if (studyGrades != null) {
            projectItem.setCurrentGrades(studyGrades.getGrades());
            projectItem.setEndGrades(projectItem.getCurrentGrades().compareTo(projectItem.getMaxGrades()) > 0 ? projectItem.getMaxGrades() : projectItem.getCurrentGrades());
        }
        return projectItem;
    }

    /**
     * 查询德育素质测评
     *
     * @return
     */
    private List<ProjectItem> getMoralData(String studentKey, Long currentTermId) {
        List<ProjectItem> projectItemList = new ArrayList<>();
        // 德育基础分
        ProjectItem moralBasicProjectItem = getMoralEducationBasic(studentKey, currentTermId);
        // 德育素质分
        ProjectItem moralQuality = getMoralQuality(studentKey, currentTermId);
        projectItemList.add(moralBasicProjectItem);
        projectItemList.add(moralQuality);
        return projectItemList;
    }

    /**
     * 德育素质分
     *
     * @param studentKey
     * @param currentTermId
     * @return
     */
    private ProjectItem getMoralQuality(String studentKey, Long currentTermId) {
        ProjectItem projectItem = new ProjectItem();
        BigDecimal maxGrades = new BigDecimal(5);
        BigDecimal currentGrades = new BigDecimal(0);
        projectItem.setKey("德育素质分");
        projectItem.setChildList(new ArrayList<>());
        projectItem.setMaxGrades(maxGrades);
        projectItem.setCurrentGrades(currentGrades);

        // 院级优秀党员...优秀团员
        List<MoralEducation> moralEducationList = iMoralEducationService.list(new QueryWrapper<MoralEducation>().lambda()
                .eq(MoralEducation::getStudentKey, studentKey)
                .eq(MoralEducation::getTermId, currentTermId));
        for (MoralEducation moralEducation : moralEducationList) {
            ProjectItem projectItem1 = new ProjectItem();
            projectItem1.setKey(MoralEducationType.getNameByCode(moralEducation.getType()));
            projectItem1.setMaxGrades(new BigDecimal(3));
            projectItem1.setCurrentGrades(MoralEducationType.getGradesByCode(moralEducation.getType()));
            projectItem1.setEndGrades(MoralEducationType.getGradesByCode(moralEducation.getType()));
            projectItem.getChildList().add(projectItem1);
        }

        // 党校学习
        PartySchool partySchool = iPartySchoolService.getOne(new QueryWrapper<PartySchool>().lambda()
                .eq(PartySchool::getStudentKey, studentKey)
                .eq(PartySchool::getTermId, currentTermId)
                .orderByDesc(BaseEntity::getCreateTime)
                .last("limit 1"));
        if (partySchool != null) {
            ProjectItem partyProjectItem = new ProjectItem();
            partyProjectItem.setKey("业余党校");
            partyProjectItem.setMaxGrades(new BigDecimal(1));
            if (partySchool.getIsMakeUp() && partySchool.getGrades().compareTo(new BigDecimal(60)) < 0) {
                // 补考且不及格
                partyProjectItem.setValue("补考不合格");
                partyProjectItem.setEndGrades(new BigDecimal(-2));
                partyProjectItem.setCurrentGrades(new BigDecimal(-2));
            } else if (!partySchool.getIsMakeUp() && partySchool.getGrades().compareTo(new BigDecimal(60)) > 0) {
                // 不是补考并且及格
                partyProjectItem.setValue("合格");
                partyProjectItem.setEndGrades(new BigDecimal(1));
                partyProjectItem.setCurrentGrades(new BigDecimal(1));
            } else if (!partySchool.getIsMakeUp() && partySchool.getGrades().compareTo(new BigDecimal(60)) < 0) {
                // 考试不及格
                partyProjectItem.setValue("考试不合格");
                partyProjectItem.setEndGrades(new BigDecimal(0));
                partyProjectItem.setCurrentGrades(new BigDecimal(0));
            } else {
                // 补考及格
                partyProjectItem.setValue("补考合格");
                partyProjectItem.setEndGrades(new BigDecimal(0));
                partyProjectItem.setCurrentGrades(new BigDecimal(0));
            }
            projectItem.getChildList().add(partyProjectItem);
        }

        // 入党积极分子
        PartyActivists partyActivists = iPartyActivistsService.getOne(new QueryWrapper<PartyActivists>().lambda()
                .eq(PartyActivists::getStudentKey, studentKey)
                .eq(PartyActivists::getTermId, currentTermId)
                .last("limit 1"));
        if (partyActivists != null) {
            ProjectItem partyActivitiesProjectItem = new ProjectItem();
            partyActivitiesProjectItem.setValue(partyActivists.getProjectName());
            partyActivitiesProjectItem.setKey("入党积极分子");
            partyActivitiesProjectItem.setMaxGrades(new BigDecimal(1));
            partyActivitiesProjectItem.setCurrentGrades(new BigDecimal(1));
            partyActivitiesProjectItem.setEndGrades(new BigDecimal(1));
            projectItem.getChildList().add(partyActivitiesProjectItem);
        }

        // 热心工艺活动 - 一条0.5
        List<PublicWelfareActivities> publicWelfareActivities = iPublicWelfareActivitiesService.list(new QueryWrapper<PublicWelfareActivities>().lambda()
                .eq(PublicWelfareActivities::getStudentKey, studentKey)
                .eq(PublicWelfareActivities::getTermId, currentTermId));
        if (publicWelfareActivities.size() > 0) {
            ProjectItem publicWelfareActivityProject = new ProjectItem();
            publicWelfareActivityProject.setKey("热心公益活动");
            publicWelfareActivityProject.setMaxGrades(new BigDecimal(1));
            publicWelfareActivityProject.setChildList(new ArrayList<>());
            for (PublicWelfareActivities publicWelfareActivity : publicWelfareActivities) {
                ProjectItem publicWelfareItem = new ProjectItem();
                publicWelfareItem.setMaxGrades(new BigDecimal("0.5"));
                publicWelfareItem.setEndGrades(new BigDecimal("0.5"));
                publicWelfareItem.setCurrentGrades(new BigDecimal("0.5"));
                publicWelfareItem.setKey(publicWelfareActivity.getTitle());
                publicWelfareActivityProject.getChildList().add(publicWelfareItem);
            }
            // 处理数据
            for (ProjectItem item : publicWelfareActivityProject.getChildList()) {
                publicWelfareActivityProject.setCurrentGrades(publicWelfareActivityProject.getCurrentGrades().add(item.getCurrentGrades()));
            }
            // 最终成绩
            publicWelfareActivityProject.setEndGrades(publicWelfareActivityProject.getCurrentGrades().compareTo(publicWelfareActivityProject.getMaxGrades()) > 0 ?
                    publicWelfareActivityProject.getMaxGrades() : publicWelfareActivityProject.getCurrentGrades());
            projectItem.getChildList().add(publicWelfareActivityProject);
        }

        // 好人好事
        List<GoodThings> goodThingsList = iGoodThingsService.list(new QueryWrapper<GoodThings>().lambda()
                .eq(GoodThings::getStudentKey, studentKey)
                .eq(GoodThings::getTermId, currentTermId));
        if (goodThingsList.size() > 0) {
            ProjectItem goodThingsProject = new ProjectItem();
            goodThingsProject.setKey("好人好事");
            goodThingsProject.setMaxGrades(new BigDecimal(2));
            goodThingsProject.setChildList(new ArrayList<>());

            for (GoodThings goodThings : goodThingsList) {
                ProjectItem goodThingsItem = new ProjectItem();
                goodThingsItem.setMaxGrades(new BigDecimal(1));
                goodThingsItem.setEndGrades(new BigDecimal(1));
                goodThingsItem.setCurrentGrades(new BigDecimal(1));
                goodThingsItem.setKey(goodThings.getTitle());
                goodThingsProject.getChildList().add(goodThingsItem);
            }
            // 处理数据
            for (ProjectItem item : goodThingsProject.getChildList()) {
                goodThingsProject.setCurrentGrades(goodThingsProject.getCurrentGrades().add(item.getCurrentGrades()));
            }
            // 最终成绩
            goodThingsProject.setEndGrades(goodThingsProject.getCurrentGrades().compareTo(goodThingsProject.getMaxGrades()) > 0 ?
                    goodThingsProject.getMaxGrades() : goodThingsProject.getCurrentGrades());
            projectItem.getChildList().add(goodThingsProject);

        }

        // 暑期三下乡
        List<SummerVolunteer> summerVolunteerList = iSummerVolunteerService.list(new QueryWrapper<SummerVolunteer>().lambda()
                .eq(SummerVolunteer::getStudentKey, studentKey)
                .eq(SummerVolunteer::getTermId, currentTermId));
        if (summerVolunteerList.size() > 0) {
            ProjectItem summerVolunteerProject = new ProjectItem();
            summerVolunteerProject.setMaxGrades(new BigDecimal(3));
            summerVolunteerProject.setKey("暑期三下乡");
            summerVolunteerProject.setChildList(new ArrayList<>());
            for (SummerVolunteer summerVolunteer : summerVolunteerList) {
                ProjectItem item = new ProjectItem();
                item.setMaxGrades(new BigDecimal(3));
                item.setKey(summerVolunteer.getProjectName());
                item.setEndGrades(new BigDecimal(3));
                item.setCurrentGrades(new BigDecimal(3));
                summerVolunteerProject.getChildList().add(item);
            }
            // 处理数据
            for (ProjectItem item : summerVolunteerProject.getChildList()) {
                summerVolunteerProject.setCurrentGrades(summerVolunteerProject.getCurrentGrades().add(item.getCurrentGrades()));
            }
            // 最终成绩
            summerVolunteerProject.setEndGrades(summerVolunteerProject.getCurrentGrades().compareTo(summerVolunteerProject.getMaxGrades()) > 0 ?
                    summerVolunteerProject.getMaxGrades() : summerVolunteerProject.getCurrentGrades());
            projectItem.getChildList().add(summerVolunteerProject);
        }

        // 学生干部任职
        List<Job> jobList = iJobService.list(new QueryWrapper<Job>().lambda()
                .eq(Job::getStudentKey, studentKey)
                .eq(Job::getTermId, currentTermId)
                .orderByAsc(Job::getType).last("limit 2"));
        if (jobList.size() > 0) {
            ProjectItem jobProject = new ProjectItem();
            jobProject.setMaxGrades(new BigDecimal(3));
            jobProject.setKey("学生干部任职");
            jobProject.setChildList(new ArrayList<>());
            for (Job job : jobList) {
                ProjectItem item = new ProjectItem();
                item.setMaxGrades(new BigDecimal(3));
                item.setKey(job.getJobName());
                item.setValue(JobType.getNameByCode(job.getType()));
                item.setEndGrades(JobType.getGradesByCode(job.getType()));
                item.setCurrentGrades(JobType.getGradesByCode(job.getType()));
                jobProject.getChildList().add(item);
            }
            // 第二类任职 * 0.4
            if (jobProject.getChildList().size() >= 2) {
                jobProject.getChildList().get(1).setEndGrades(jobProject.getChildList().get(1).getEndGrades().multiply(new BigDecimal("0.4")));
            }
            // 处理数据
            for (ProjectItem item : jobProject.getChildList()) {
                jobProject.setCurrentGrades(jobProject.getCurrentGrades().add(item.getCurrentGrades()));
            }

            // 最终成绩
            jobProject.setEndGrades(jobProject.getCurrentGrades().compareTo(jobProject.getMaxGrades()) > 0 ?
                    jobProject.getMaxGrades() : jobProject.getCurrentGrades());
            projectItem.getChildList().add(jobProject);
        }

        // 文化传播
        List<CulturalTransmission> culturalTransmissionList = iCulturalTransmissionService.list(new QueryWrapper<CulturalTransmission>().lambda()
                .eq(CulturalTransmission::getStudentKey, studentKey)
                .eq(CulturalTransmission::getTermId, currentTermId));

        if (culturalTransmissionList.size() > 0) {
            ProjectItem culturalTransmissionProject = new ProjectItem();
            culturalTransmissionProject.setKey("文化传播");
            culturalTransmissionProject.setChildList(new ArrayList<>());
            culturalTransmissionProject.setMaxGrades(new BigDecimal(99));
            for (CulturalTransmission culturalTransmission : culturalTransmissionList) {
                ProjectItem item = new ProjectItem();
                item.setKey(culturalTransmission.getTitle());
                item.setMaxGrades(new BigDecimal(6));
                item.setCurrentGrades(culturalTransmission.getApplyFraction());
                item.setEndGrades(culturalTransmission.getApplyFraction().compareTo(item.getMaxGrades()) > 0 ?
                        item.getMaxGrades() : culturalTransmission.getApplyFraction());
                culturalTransmissionProject.getChildList().add(item);
            }

            // 计算
            for (ProjectItem item : culturalTransmissionProject.getChildList()) {
                culturalTransmissionProject.setCurrentGrades(item.getCurrentGrades().add(culturalTransmissionProject.getCurrentGrades()));
            }

            culturalTransmissionProject.setEndGrades(culturalTransmissionProject.getCurrentGrades().compareTo(culturalTransmissionProject.getMaxGrades()) > 0 ?
                    culturalTransmissionProject.getMaxGrades() : culturalTransmissionProject.getCurrentGrades());
            projectItem.getChildList().add(culturalTransmissionProject);
        }

        // 总的计算
        for (ProjectItem item : projectItem.getChildList()) {
            currentGrades = currentGrades.add(item.getEndGrades());
        }
        projectItem.setCurrentGrades(currentGrades);
        projectItem.setEndGrades(currentGrades.compareTo(projectItem.getMaxGrades()) > 0 ? maxGrades : currentGrades);
        return projectItem;
    }

    /**
     * 德育基础分
     *
     * @param studentKey
     * @param currentTermId
     * @return
     */
    private ProjectItem getMoralEducationBasic(String studentKey, Long currentTermId) {
        MoralEducationBasic moralEducationBasic = iMoralEducationBasicService.getOne(new QueryWrapper<MoralEducationBasic>()
                .lambda()
                .eq(MoralEducationBasic::getStudentKey, studentKey)
                .eq(MoralEducationBasic::getTermId, currentTermId).last("limit 1"));

        ProjectItem projectItem = new ProjectItem();
        projectItem.setKey("德育基础分");
        projectItem.setChildList(new ArrayList<>());
        projectItem.setMaxGrades(new BigDecimal(8));
        projectItem.setValue("一项不符合扣4分，扣完为止");

        if (moralEducationBasic == null) {
            // 没有初始化
            projectItem.setValue("未初始化");
            return projectItem;
        }
        ProjectItem projectItem1 = new ProjectItem();
        projectItem1.setKey("是否遵守社会功德");
        projectItem1.setMaxGrades(new BigDecimal(4));
        if (moralEducationBasic.getDoMoral()) {
            projectItem1.setValue("是");
            projectItem1.setCurrentGrades(new BigDecimal(4));
            projectItem1.setEndGrades(new BigDecimal(4));
        } else {
            projectItem1.setValue("否");
            projectItem1.setCurrentGrades(new BigDecimal(0));
            projectItem1.setEndGrades(new BigDecimal(0));
        }
        ProjectItem projectItem2 = new ProjectItem();
        projectItem2.setKey("是否践行社会主义核心价值观");
        projectItem2.setMaxGrades(new BigDecimal(4));
        if (moralEducationBasic.getDoCoreValue()) {
            projectItem2.setValue("是");
            projectItem2.setCurrentGrades(new BigDecimal(4));
            projectItem2.setEndGrades(new BigDecimal(4));
        } else {
            projectItem2.setValue("否");
            projectItem2.setCurrentGrades(new BigDecimal(0));
            projectItem2.setEndGrades(new BigDecimal(0));
        }
        ProjectItem projectItem3 = new ProjectItem();
        projectItem3.setKey("是否坚持四项基本原则");
        projectItem3.setMaxGrades(new BigDecimal(4));
        if (moralEducationBasic.getFourPrinciple()) {
            projectItem3.setValue("是");
            projectItem3.setCurrentGrades(new BigDecimal(4));
            projectItem3.setEndGrades(new BigDecimal(4));
        } else {
            projectItem3.setValue("否");
            projectItem3.setCurrentGrades(new BigDecimal(0));
            projectItem3.setEndGrades(new BigDecimal(0));
        }

        projectItem.getChildList().add(projectItem1);
        projectItem.getChildList().add(projectItem2);
        projectItem.getChildList().add(projectItem3);


        for (ProjectItem item : projectItem.getChildList()) {
            projectItem.setCurrentGrades(item.getCurrentGrades().add(projectItem.getCurrentGrades()));
        }
        projectItem.setEndGrades(projectItem.getCurrentGrades().compareTo(projectItem.getMaxGrades()) > 0 ? projectItem.getMaxGrades() : projectItem.getCurrentGrades());
        if (projectItem.getEndGrades().compareTo(new BigDecimal(4)) <= 0) {
            projectItem.setEndGrades(new BigDecimal(0));
        }
        return projectItem;
    }
}
